<template>
  <div style="display: none">
    <audio ref="myAudio" id="myaudio" :src="currMp3Url" loop="false" v-if="currMp3Url"/>
  </div>
</template>

<script>
export default {
  name: 'PlayMusic',
  data:function () {
    return {
      playShow:false,
      currMp3Url:'',
      urlMap:{
        Order:'/static/mp3/new-order.mp3',
        OrderApply:'/static/mp3/new-order-apply.mp3',
      }
    }
  },
  mounted () {
    let $this=this
    $this.bus.$on('PlayMusicCallBus',function (type) {
      $this.play(type)
    })
  },
  methods:{
    play:function (type) {
      let $this=this
      $this.currMp3Url=$this.urlMap[type]

      var timerOuter=10000
      if (type==='OrderApply'){
        timerOuter=4600
      }
      $this.$forceUpdate()
      setTimeout(function () {
        $this.$refs['myAudio'].play()
      },2000)

      setTimeout(function () {
        $this.currMp3Url=''
        $this.$forceUpdate()
      },timerOuter)
    }
  }
}
</script>

<style scoped>

</style>
